#!/bin/bash

# ----------------------------------------------------------------------
# Filename:   http_service.sh
# Version:    1.0
# Date:       2013/10/16
# Author:     huijing.hei
# Email:      huijing.hei@cs2c.com.cn
# Summary:    02系统基本功能-04网络服务-08Apache-01字符模式-01服务控制和状态查询
# Notes:       ***
# Copyright:    China Standard Software Co., Ltd.
# History：     
#             Version 1.0, 2013/10/16
#             - Start httpd service.
# ----------------------------------------------------------------------

##! @TODO: start&stop http service
##! @AUTHOR: huijing.hei
##! @VERSION: 1.0 
##! @OUT: 0 => success; 1 => failure

function do_test()
{
    serv=httpd

    status_daemon ${serv}

    # start
    if [ $? -ne 0 ]
    then
        echo "${serv} is stopped"
        start_daemon ${serv}
        EchoResult "service ${serv} start"
    else
        echo "${serv} is running..."
    fi

    # check httpd start
    status_daemon ${serv}
    netstat -nlutp | grep ${serv}
    EchoResult "service ${serv} status: start"

    sleep 3

    # restart
    restart_daemon ${serv}
    EchoResult "service ${serv} restart"

    # check httpd restart
    status_daemon ${serv}
    netstat -nlutp | grep ${serv}
    EchoResult "service ${serv} status: restart"

    sleep 3


    # stop
    stop_daemon ${serv}
    EchoResult "service ${serv} stop"

    # check httpd stop
    status_daemon ${serv}
    netstat -nlutp | grep ${serv}
    if [ $? -ne 0 ]
    then
        echo "PASS: service ${serv} status: stop"
    else
        echo "FAIL: service ${serv} status: stop"
        exit 1
    fi

}


# include lib files

if [ -z "$SFROOT" ]
then
    CMDLIB=./
    SFROOT=./
else
    CMDLIB=${SFROOT}/testcases/Network_Service
fi

. ${SFROOT}/lib/Echo.sh
. ${CMDLIB}/lib/Net.sh

do_test
EchoResult "testcase: ${serv} start,stop,restart"
